<?php
class classSimpleMessage extends phpajax {
    function input(){
        aread('simpleMessage_operation'); //values: SAVE_DATA, SHOW_RESULT, ""
        //--------------------------------------
        aread('smName');
        aread('smSurname');
        aread('smEmail');
        aread('smSubject');
        aread('smText');
    }

    function loading() {} 

    function main() {        
        $_Window  = new classWindow();
        $_SmForms = new classSimpleMessageForms();
        
        if($this->simpleMessage_operation==''){
            aprint('flow_container2', $_Window->ShowByAJAX('flow_container2',$_SmForms->getForm()));
        }
        
        if($this->simpleMessage_operation=='SAVE_DATA'){
            $aasSM_InputValues =  $this->makeAssocArrayForSM();
            if(trim($aasSM_InputValues['smSubject'])!='' and trim($aasSM_InputValues['smText'])!=''){
                $_SmData = new classSimpleMessageData();
                if(!$_SmData->Insert($aasSM_InputValues))
                    aprint('sm_error_message_container', _i18n_simplemessages_ERROR_DURING_SENDING_OF_MESSAGE_YOU_CAN_TRY_IT_AGAIN_WHILE_A_TIME);
                else
                    aprint('flow_container2', $_Window->ShowByAJAX('flow_container2','
                      <br><br>'.
                      _i18n_simplemessages_MESSAGE_WAS_SUCCESSFULL_SENT_NOW_YOU_CAN_CLOSE_THIS_WINDOW_.
                      '<br><br>'.
                      '
                      <a href="'._URL_INACTIVE_ADDR_.'"
                        onclick="
                          document.getElementById(\'shadow_container\').style.visibility=\'hidden\';
                          document.getElementById(\'User_Operation\').value = \'jsd_UO_CloseWindow\';
                          classUsers();
                        "
                      >
                        '._i18n_user_CLOSE_.'
                      </a>
                      '.
                      '<br><br>'
                    ));
            }
            else
                aprint('sm_error_message_container', _i18n_simplemessages_FIELDS_MARKED_BY_STAR_ARE_REQUIRED_PLEASE_FILL_THEM_BEFORE_SENDING_YOUR_MESSAGE);
        }
        
        
        
    }
    
    private function makeAssocArrayForSM(){
        $_Input = new classInput();
        
        $aasValues['smName']    = trim($_Input->Sterilize($this->smName));
        $aasValues['smSurname'] = trim($_Input->Sterilize($this->smSurname));
        $aasValues['smEmail']   = trim($_Input->Sterilize($this->smEmail));
        $aasValues['smSubject'] = trim($_Input->Sterilize($this->smSubject));
        $aasValues['smText']    = trim($_Input->Sterilize($this->smText));
        
        return $aasValues;
    }
    
}
?>
